package com.expoente.controller;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.expoente.DroidBusConstants;

public class DatabaseHelper
		extends SQLiteOpenHelper {

	public DatabaseHelper(Context context) {
		super(context, DroidBusConstants.DATABASE_NAME, null,
				DroidBusConstants.DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		createTables(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		dropTables(db);
		onCreate(db);
	}

	@Override
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);		
	}

	public void dropTables(SQLiteDatabase db) {
		db.execSQL(DroidBusConstants.DROP_TABLE_LINE);
		db.execSQL(DroidBusConstants.DROP_TABLE_PLACE);
		db.execSQL(DroidBusConstants.DROP_TABLE_ROUTE);
	}

	public void createTables(SQLiteDatabase db) {
		db.execSQL(DroidBusConstants.CREATE_LINE);
		db.execSQL(DroidBusConstants.CREATE_PLACE);
		db.execSQL(DroidBusConstants.CREATE_ROUTE);
	}
}
